<?php
    require_once(APPPATH . '/controllers/test/Toast.php');

    class Groups_tests extends Toast
    {
        var $ins_id;
        var $groups_data;
        var $default_groups = FALSE;

        function __construct()
        {
            parent::__construct(__FILE__);
            $this->load->model('groups_model');
            // Load any models, libraries etc. you need here
        }

        /**
        * OPTIONAL; Anything in this function will be run before each test
        * Good for doing cleanup: resetting sessions, renewing objects, etc.
        */
        function _pre() {}

        /**
        * OPTIONAL; Anything in this function will be run after each test
        * I use it for setting $this->message = $this->My_model->getError();
        */
        function _post() {}


        /* TESTS BELOW */

        function test_simple_group_creating()
        {

            $this->groups_data = array(
                array(
                    'ID' => $this->config->item('general_ID'),
                    'name'=>'General',
                    'custom'=>0
                ),
                array(
                    'ID' => $this->config->item('meals_ID'),
                    'name'=>'Meals',
                    'custom'=>0
                ),
                array(
                    'ID' => $this->config->item('beaches_ID'),
                    'name'=>'Beaches',
                    'custom'=>0
                ),
                array(
                    'ID' => $this->config->item('distance_from_ID'),
                    'name'=>'Distance from',
                    'custom'=>0
                ),
                array(
                    'ID' => $this->config->item('additional_activities_nearby_ID'),
                    'name'=>'Additional activities nearby',
                    'custom'=>0
                ),
                array(
                    'ID' => $this->config->item('hotel_equipment_and_offerings_ID'),
                    'name'=>'Hotel equipment and offerings',
                    'custom'=>0
                ),
                array(
                    'ID' => $this->config->item('all_accommodation_units_are_equiped_with_ID'),
                    'name'=>'All accommodation units are equiped with',
                    'custom'=>0
                ),
                array(
                    'ID' => $this->config->item('location_ID'),
                    'name'=>'Location',
                    'custom'=>0
                ),
                array(
                    'ID' => $this->config->item('description_ID'),
                    'name'=>'Description',
                    'custom'=>0
                )
            )
            ;

            if($this->default_groups)
                foreach ($this->groups_data as $row):
                    $inser_id = $this->groups_model->insert($row);
                    $this->firephp->log($inser_id);
                    $this->_assert_true($inser_id); // true*/
                    endforeach;

            $this->_assert_true($this->default_groups);

        }

        function test_default_groups_exists()
        {
            // Check if method exists
            $exists = (int)method_exists($this->groups_model, 'view_all_groups');
            $this->_assert_true($exists);

            //check view_all groups -> 0 default, 1 custom
            $all_groups = $this->groups_model->view_all_groups(0);
            //$this->firephp->log($all_groups);

            $this->_assert_not_empty($all_groups); // true*/

            $default_group_count = count($this->groups_data);

            for($i=0;$i<$default_group_count;$i++){
                //$this->firephp->log($this->groups_data[$i]['name']);
                //$this->firephp->log($all_groups[$i]['name']);
                $this->_assert_equals($this->groups_data[$i]['name'],$all_groups[$i]['name']);
            }

            // description to the unit test results page:
            $this->message = '$all_groups ==  $this->groups_data';
        }

        function test_add_group()
        {
            // Check if method exists
            $exists = (int)method_exists($this->groups_model, 'insert');
            $this->_assert_true($exists);

            // check insert group
            $data = array(
                'name'=>'test',
                'custom'=>0
            );
            $this->ins_id = $this->groups_model->insert($data);
            //$this->firephp->log($this->ins_id);
            $this->_assert_true($this->ins_id); // true*/

        }

        function test_delete_group()
        {
            // Check if method exists
            $exists = (int)method_exists($this->groups_model, 'delete_group');
            $this->_assert_true($exists);

            //check delete group
            $delete_res = $this->groups_model->delete_group($this->ins_id);
            //$this->firephp->log($delete_res);
            $this->_assert_true($delete_res);
        }

    }

    // End of file example_test.php */
    // Location: ./system/application/controllers/test/example_test.php */